<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
</head>
<body>
<form action="user/login" >
    用户名：<input type="text" name="username" placeholder="请输入用户名">
    <br>
    密码：<input type="password" name="password" placeholder="请输入密码">
    <br>
    <input type="submit" value="提交">
</form>
<br><br>
<form id = "ajax_form">
    用户名：<input type="text" name="username" placeholder="请输入用户名">
    <br>
    密码：<input type="password" name="password" placeholder="请输入密码">
    <br>
    <input type="submit" value="提交">
</form>

<script src="static/jquery@3.3.1/jquery.min.js"></script>
<script>
$(function(){
    $("#ajax_form").submit(function () {
        let data = {
            username:"abc",
            password:"123",
        };
        $.ajax({
            url:"user/login2",//请求路径
            type:"post",//请求方法
            contentType:"application/json",
            data:JSON.stringify(data),
            dataType:"json",//响应的数据格式
            success:function(r){
                alert(JSON.stringify(r))
            },error:function (jq) {
                alert("状态码："+jq.status+",错误消息："+jq.statusText)
            }
        })
    })
})
</script>
</body>
</html>
